package views
{
	import flash.events.GeolocationEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.sensors.Geolocation;
	
	import inerface.IMapPanel;
	
	import main.ClientConstants;
	import main.ViewSubBase;
	
	import panel.mapPanel.MapPanel;
	
	import struct.Hotel;
	import struct.Restaurant;
	import struct.Scenic;
	import struct.ScenicShop;
	
	public class SelectPathView extends ViewSubBase
	{
		private var _panel:IMapPanel;
		
		private var geoloc:Geolocation = new Geolocation();
		
		public var pathList:Array = [];
		
		public var titleStr:String = "";
		
		public function SelectPathView()
		{
			
		}
		
		public override function show():void
		{
			render();
		}
		
		protected override function render():void
		{
			if(_panel == null){
				_panel = new MapPanel;
				_panel.init(view.layout.stage,view.resourceLoader,view.lang,view.uri);
				_panel.showDetail = onShowDetail;
				_panel.showSysPath = showSysPath;
				_panel.onSwapToMap = swapToMap;
			}
			
			this.addView(_panel);
			_panel.showMap(pathList,titleStr);
		}
		
		private function showSysPath():void
		{
			view.sysRecommendPathList.show();
		}
		
		private function getLocation():void
		{
			if(Geolocation.isSupported){
				if(geoloc.muted == false){
					geoloc.addEventListener(GeolocationEvent.UPDATE,onGeoUpdataHandler);
				}
			}
		}
		
		protected function onGeoUpdataHandler(e:GeolocationEvent):void
		{
			geoloc.removeEventListener(GeolocationEvent.UPDATE,onGeoUpdataHandler);
			
			var lat:Number = e.latitude;
			var lon:Number = e.longitude;
			
			if(_panel){
				_panel.showMap([lat,lon]);
			}
		}
		
		public override function clear():void
		{
			if(_panel){
				_panel.clear();
				_panel = null;
			}
		}
		
		public override function close():void
		{
			view.layout.closeView(this);
		}
		
		private function onShowDetail(obj:*):void
		{
			if(obj != null){
				
				var _type:int = 0;
				
				if(obj is Restaurant){
//					view.shopDetail.shopId = obj.id;
//					view.shopDetail.show();
					
					_type = ClientConstants.DETAIL_EAT;
				}
				if(obj is ScenicShop){
//					view.scenicShopDetail.shopId = obj.id;
//					view.scenicShopDetail.show();
					
					_type = ClientConstants.DETAIL_SHOP;
				}
				if(obj is Scenic){
					
					_type = ClientConstants.DETAIL_VIEWSPOT;
				}
				if(obj is Hotel){
					
					_type = ClientConstants.DETAIL_HOUSE;
				}
				
				view.viewSpotDetail.showData(obj,_type);
			}
		}
		
		private function swapToMap(list:Array):void
		{
			view.mapContainer.info = list;
			view.mapContainer.show();
		}
	}
}